<?php

class Alblum_process extends CI_Model {//这里关于admin表的一些操作和登录判定

    const Statustrue = True;
    const Statusflase = False;

    function __construct() {
        parent::__construct();
         $this->load->helper('url');
           $this->load->library('file_upload'); //引入类库
    }

    function album_type_array($type) {
        $sql = "select * from album where type=\"{$type}\"";
        $query = $this->db->query($sql);
        return $res = $query->result_array();
    }
    
    function album_type_array_admin($isno_type) {
        $sql = "select * from album where type != \"{$isno_type}\"";
        $query = $this->db->query($sql);
        return $res = $query->result_array();
    
    }
//
//     function get_album_type_by_id($id){
//       $sql = "select * from album  where id=\"{$id}\" ";
//        $query = $this->db->query($sql);
//        return $res = $query->result_array();
//         
//         
//     }
    
    
    
    
    
    function add_album($post_array) {

        $insertsql = "insert into album(
title,
`desc`,
cover,
type,
`order`
) values(\"{$post_array["title"]}\",\"{$post_array["desc"]}\",\"{$post_array["cover"]}\",\"{$post_array["album_type"]}\",\"{$post_array["order"]}\")";

        $this->db->query($insertsql);
    }
    
     function update_album($id) {
      $config['upload_path'] = './uploads/album'; //设定上传存储路径
        $data = $this->file_upload->upLoadfile($config, "cover");      
           if (isset($data)) {
            $siteurl = site_url(); //$siteurl .
            $config["source_image"] = $data["full_path"];
            $config["new_image"] = './uploads/album/thum';
            $this->file_upload->process_img($config);
            $post_array["full_path"] = "{$data["file_name"]}"; //获得新的图片名称对应数据库中banner字段            
            //同步更新数据库记录
            $_POST["desc"]=htmlspecialchars($_POST["desc"]);
     $update_sql = "update album set title=\"{$_POST["title"]}\",`desc`=\"{$_POST["desc"]}\",cover=\"{$post_array["full_path"]}\",`order`=\"{$_POST["order"]}\"
                where id=\"{$id}\"";
        } else {            
            //不更新图片链接，同步更新数据库
                 $_POST["desc"]=htmlspecialchars($_POST["desc"]);
    $update_sql = "update album set title=\"{$_POST["title"]}\",`desc`=\"{$_POST["desc"]}\",`order`=\"{$_POST["order"]}\"
                where id=\"{$id}\"";
        }
        $query = $this->db->query($update_sql);   
         
         
         
         
         
     }
}

?>
